package debug_whitebox;

import static org.junit.Assert.assertEquals;

import java.lang.reflect.Field;

import javax.swing.JTextArea;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import debug.apple_debug;

//import blackjack.apple_mod;

/* CONTROL METHOD SPECIFICATION
 * INPUTs: p - CHECKED_OUTPUTs: res, area
 * 1. 	The method receives an integer (p) which identify a specific card,
 * 		verify if it is a figure, returns relative value and print the associated 
 * 		card into a TextArea.
 * 2.   Values must be in [1,13]. 
 * 3.	FIGURES: p=1->'A'; p=11->'J'; p=12->'Q'; p=13->'K';
 * 4.   The figure value is 10.
 * 5.	'A' value is only 11 (not also 1). The outer module will correct this value 
 * 		if necessary.
 * 6.	Every p not in [1,13] has value 10. 
 *
 *The CFG generated with a tool of eclipse show the McGaber result is 6.
 *Then we need 6 test to cover all code and test it.
 *
 * TESTS SUMMARY
 * 
 * 	1: p in [2,10]
 *	2: p = 1
 *	3: p = 11
 *	4: p = 12
 *	5: p = 13
 * 	6: p = 15
 *
 */

public class TestControl {
	
	private apple_debug test;
	private JTextArea area;
	private String areaString;
	
	private Class testClass;
	
	/*
	 * Precondizioni
	 * E' necessario riportare ogni volta lo stato dell'oggetto da testare
	 * in uno stato iniziale
	 */
	@Before
	public void setUp() throws Exception {
		test = new apple_debug();
		
		testClass = test.getClass();
		
		Field areaStringField = testClass.getDeclaredField("area");
		areaStringField.setAccessible(true);
		
		
		area = (JTextArea)areaStringField.get(test);
		
		areaString = area.getText();
	}

	@After
	public void tearDown() throws Exception {
	}
	
	//Test 1: p in [2,10]
	@Test
	public void testControlWB1() {
		
		assertEquals(5,test.control(5));
		assertEquals(areaString+" 5",area.getText());
	}
	
	
	//Test 2: p = 1
	@Test
	public void testControlWB2() {
		assertEquals(11,test.control(1));
		assertEquals(areaString+" A",area.getText());
	}
	

	 //Test 3: p = 13
	@Test
	public void testControlWB3() {
		assertEquals(10,test.control(13));
		assertEquals(areaString+" K",area.getText());
	}
	
	 
	//Test 4: p = 12
	@Test
	public void testControlWB4() {
		assertEquals(10,test.control(12));
		assertEquals(areaString+" Q",area.getText());
	}
	

	 //Test 5: p = 11 
	@Test
	public void testControlWB5() {
		assertEquals(10,test.control(11));
		assertEquals(areaString+" J",area.getText());
	}
	
	
	//Test 6: p = 15
	@Test
	public void testControlWB6() {
		assertEquals(10,test.control(15));
		assertEquals(areaString,area.getText());
	}
	
}
